// search模块小仓库
import { reqGetSearchInfo } from "@/api"
const state = {
  searchList: {}
}
const mutations = {
  GETSEARCHLIST (state, searchList) {
    state.searchList = searchList
  }
}
const actions = {
  async getSearchList (context, params={}) {
    const {data: res} = await reqGetSearchInfo(params)
    if (res.code == 200) {
      context.commit('GETSEARCHLIST', res.data)
    }
  }
}

// 计算属性 简化数据
// 将来组件获取数据的时候方便
const getters = {
  // state并非大仓库，当前仓库的state
  goodsList (state) {
    // 这样写有问题  没网的话服务器数据没回来 就是undefined searchList是空对象
    return state.searchList.goodsList || []
  },
  trademarkList (state) {
    return state.searchList.trademarkList
  },
  attrsList (state) {
    return state.searchList.attrsList
  }
}

export default {
  state,
  mutations,
  actions,
  getters
}